package first;

/**
 * 用面向对象的方式来写一个计算机程序，意在把界面和业务代码分开来写，从而达到业务代码的高可用性。
 * @author Seon
 * @date 2022/10/27 23:19
 */
public class Operation {
    public static double getResult(Double numberA, Double numberB, String operate) {
        double result = 0;
        switch (operate) {
            case "+":
                result = numberA + numberB;
                break;
            case "-":
                result = numberA - numberB;
                break;
            case "*":
                result = numberA * numberB;
                break;
            case "/":
                if (numberB == 0) {
                    System.out.println("除数不能为0");
                    System.exit(1);
                }
                result = numberA / numberB;
                break;
        }

        return result;
    }
}
